package com.cqhfan.imservice.handler;

import org.springframework.web.socket.WebSocketSession;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 眭传洪
 * @create 2025-08-16 2:33
 */
public class UserConnectionSession {

    public static final Map<Long, WebSocketSession> USER_CONNECTION_MAP = new ConcurrentHashMap<>();

    public static void addConnectionRelation(Long userId, WebSocketSession session) {
        USER_CONNECTION_MAP.put(userId, session);
    }

    public static void removeConnectionRelation(Long userId) {
        USER_CONNECTION_MAP.remove(userId);
    }

    public static WebSocketSession getConnectionRelation(Long userId) {
        return USER_CONNECTION_MAP.get(userId);
    }

    public static Set<Long> getConnectionUserIds() {
        return new HashSet<>(USER_CONNECTION_MAP.keySet());
    }

}
